/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package GUI.Components;

import Tools.ACommand;
import Tools.CMDThreadGUI;
import Tools.TModel;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 *
 * @author Иван
 */
public class PanelButtonsDrivers extends AComponentBuilder {

    private List<String> commands = new ArrayList<String>(0);
    private final TModel model;
    private JPanel panel = new JPanel();
    private final AObserverGUI observerGUI;
    private String dir;

    public PanelButtonsDrivers(TModel model, AObserverGUI observerGUI) {
        this.observerGUI = observerGUI;
        this.model = model;
    }
    private ActionListener action = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Activate();
            dir = e.getActionCommand();

            observerGUI.setCommandThread(new CMDThreadGUI("cd" + " " + dir, observerGUI));
        }
    };

    @Override
    public JPanel buildComponent() throws Exception {
        panel.setBackground(Color.blue);

        JButton button;

        File[] drivers = File.listRoots();

        for (File f : drivers) {
            button = new JButton(f.getPath());
            button.addActionListener(action);
            panel.add(button);
        }

        return panel;
    }

    @Override
    public void updateComponent(Object object) {
    }

    public String getUserCommand(String commandName) {
        return observerGUI.buildCommand(commandName);
    }
}
